from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
import time


# 设置浏览器、启动浏览器
def create_driver():
    options = Options()
    options.add_argument('--no-sandbox')
    options.add_experimental_option("detach", True)
    driver_edge = webdriver.Edge(options=options)
    return driver_edge
driver = create_driver()

driver.get("https://www.bilibili.com/")
# 元素定位 - CSS_SELECTOR
# 1. #id
# 2. .class
# 3. 标签名
# 4. [属性名='精准值']
# 5. [属性名*='模糊值']
# 6. [属性名^='开头值']
# 7. [属性名$='结尾值']
# 以上这些都属于理论定位法

# 8. 更简单的定位方式，直接控制台复制SELECTOR
tar_list = driver.find_elements(By.CSS_SELECTOR, '[target="_blank"]')
i = 0
for tar in tar_list:
    i += 1
print(f"总共找到了{i}个元素")


